﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Informaiton_Retrieval.com.ir.utli;
using Informaiton_Retrieval.com.ir.Model;

namespace Informaiton_Retrieval
{
    public partial class MainForm : Form
    {
        PresentationModel presentation;
        public MainForm()
        {
            InitializeComponent();
            MainForm.CheckForIllegalCrossThreadCalls = false;
            presentation = new PresentationModel();
            presentation.SomeThingEvent += setOpenEnable;
            presentation.SetProgressEvent += setProgress;
            presentation.SetMeaasgeEvent += setLabel;
            presentation.SomeThingEvent2 += setSaveEnable;
            saveToolStripMenuItem.Enabled = false;
            caseFoldingBox.Checked = true;
            stopwordRemovalBox.Checked = true;
            stemmingBox.Checked = true;
        }

        private void openButton_Click(object sender, EventArgs e)
        {
            presentation.OnLoadFile();
        }

        private void setOpenEnable(bool value)
        {
            this.openToolStripMenuItem.Enabled = value;
            caseFoldingBox.Enabled = value;
            stopwordRemovalBox.Enabled = value;
            stemmingBox.Enabled = value;
        }

        private void setSaveEnable(bool value)
        {
            this.saveToolStripMenuItem.Enabled = value;
        }

        private void setProgress(int value){
            this.progressBar1.Value = value;
        }

        private void setLabel(string message) {
            this.label1.Text = message;
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            presentation.OnSaveOutput();
        }

        private void optionBox_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox cb=(CheckBox)sender;
            if (sender == caseFoldingBox)
                presentation.CaseFold=cb.Checked;
            if (sender == stopwordRemovalBox)
                presentation.Stopword=cb.Checked;
            if (sender == stemmingBox)
                presentation.Stemming=cb.Checked;
        }

    }
}
